<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" >

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-3.3.7-dist/css/bootstrap.min.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-treeview/bootstrap-treeview.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-treeview/bootstrap-treeview.min.css}">
<script type="text/javascript" th:src="@{/js/bootStrap-addTabs/bootstrap.addtabs.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootStrap-addTabs/bootstrap.addtabs.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-table/bootstrap-table.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-table/bootstrap-table.min.css}">

<script type="text/javascript" th:src="@{/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput/js/locales/zh.js}"></script>

</head>
<body>

<!-- 修改模态框（Modal） -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel1">修改商品</h4>
            </div>
            <div class="modal-body">
                <form id="myForm1">
                    <input type="hidden" class="form-control" name="coupon_id" id="coupon_id"  >
                    优惠券类型：<select id="coupon_type" name="coupon_type">
                                <option value="0">--请选择--</option>
                                <option value="1">全场赠券</option>
                                <option value="2">会员赠券</option>
                                <option value="3">购物赠券</option>
                                <option value="4">注册赠券</option>
                             </select>
                    优惠券名称：<input type="text" class="form-control" name="coupon_describe" id="coupon_describe"   placeholder="商品名称">
                    面额：<input type="text" class="form-control" name="coupon_discount" id="coupon_discount" >
                    优惠券状态： <select id="coupon_state" name="coupon_state">
                                <option value="1">全场通用</option>
                                <option value="2">指定分类</option>
                                <option value="3">指定商品</option>
                            </select>
                </form>
            </div>
            <!--  ====================================================   -->

            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" onclick="reset()" type="button">关闭</button>
                <button class="btn btn-primary" type="button" onclick="sub()">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>












<div id="tb">
    优惠券名称：<input type="text" class="form-control"  id="dname" name="coupon_describe" placeholder="优惠券名称">
    优惠券类型：
    <select id="dtype" name="coupon_type" >
        <option value="">全部</option>
        <option value="1">全场赠券</option>
        <option value="2">会员赠券</option>
        <option value="3">购物赠券</option>
        <option value="4">注册赠券</option>
    </select>
    <button type="button" onclick="sousuo()" class="btn btn-info">搜索</button>
</div>



<button class="btn btn-primary"  data-toggle="modal" data-target="#myModal1">添加</button>
 <!-- 查询列表-->
<table id="myTable"></table>





</body>
<script >
    function sousuo(){
        $("#myTable").bootstrapTable("refresh", {
            "query": {
                coupon_describe: $("#dname").val(),
                coupon_type: $("#dtype").val()
            }
        });
    }


    $("#myTable").bootstrapTable({
        url:"getListDis",
        columns:[
            {field:"xuan",checkbox:true},
            {field:"coupon_id",title:"编号"},
            {field:"coupon_describe",title:"优惠券名称"},
            {field:"coupon_type",title:"优惠券类型"},
            {field:"coupon_state",title:"优惠券状态",formatter:function (value){
                if (value==1){
                    return "可领取";
                }if (value==2){
                    return "不可领取";
                    }
                }},
            {field:"coupon_discount",title:"面值"},
            {field:"cxz",title:"操作",formatter:function(value,row){
                    var str='<button class="btn btn-info" onclick="del('+row.coupon_id+')">删除</button>';
                    var str2='<button class="btn btn-primary" onclick="getProId('+row.coupon_id+')" data-toggle="modal" data-target="#myModal1">修改</button>';
                    return str+"   "+str2;
                }},
        ],
        pagination:true,
        pageSize:10,
        pageList:[2,4,6,8,10],
        sidePagination: "client",
        toolbar:"#tb",
    })

    //修改回显
    function getProId(product_id){
        $.ajax({
            url:"getDisById",
            data:{id:product_id},
            type:"post",
            dataType:"json",
            success:function(data){
                $("#coupon_id").val(data.coupon_id);
                $("#coupon_describe").val(data.coupon_describe);
                $("#coupon_type").val(data.coupon_type);
                $("#coupon_state").val(data.coupon_state);
                $("#coupon_discount").val(data.coupon_discount);
            }
        })
    }
    //修改
    function sub(){
        $.ajax({
            url:"updDis",
            type:"post",
            data:$("#myForm1").serialize(),
            success:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');
            },error:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');

            }
        })
        $("#myForm1").form('clear');

    }

    function del(coupon_id){
        $.ajax({
            url:"delDis",
            data:{id:coupon_id},
            success:function(){
                //bootbox.confirm("成功", "info")
                $("#myTable").bootstrapTable('refresh');
            },
            error:function (){
                $("#myTable").bootstrapTable('refresh');
            }
        })
    }



</script>
</html>